package com.anjie.powerproject.service.impl;

import com.anjie.powerproject.service.QLExpressService;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class QLExpressServiceImpl implements QLExpressService {

    @Autowired
    ExpressRunner runner;

    @Override
    public boolean isUpgrade(String script) {
        try {
            Object result = runner.execute(script, new DefaultContext<>(), new ArrayList<>(), true, false);
            return (boolean) result;
        } catch (Exception ex) {
            throw new RuntimeException(String.format("表达式执行失败 script:%s", script));
        }
    }
}
